package com.atguigu.eduService.controller;


import com.atguigu.common.Result;
import com.atguigu.eduService.entity.subject.OneSubject;
import com.atguigu.eduService.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author smday
 * @since 2020-07-27
 */
@RestController
@RequestMapping("/edu/subject")
//@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    /**
     * 添加课程分类,获取上传过来的文件,把文件内容的读取出来
     */
    @PostMapping
    public Result add(@RequestParam("file")MultipartFile file){

        subjectService.add(file,subjectService);
        return Result.ok();
    }

    /**
     * 树形结构分类列表
     */
    @GetMapping
    public Result getTree(){
        List<OneSubject> list = subjectService.getAllSubjects();
        return Result.ok().data("list",list);
    }

}

